program test_03_keys;

{*
Test and debuging of the keyboard
}

uses SysUtils, gl, glu, glut, opengls, debugs, keyboards, fpscounters;

procedure OnDisplay; cdecl;
begin
  // OpenGL soap
  glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
  glLoadIdentity;

  // extra rotation using keyboard
  {
  if KeyIsDown(vkUp) then  xrot := xrot + 5;
  if KeyIsDown(vkDown) then xrot := xrot - 5;
  if KeyIsDown(vkLeft) then  zrot := zrot + 5;
  if KeyIsDown(vkRight) then zrot := zrot - 5;
  }
  if KeyIsDown(vkSmallD) then DebugKeyboard;
  if KeyIsDown(vkCapitalD) then
  begin
    DebugKeyboard;
    readln;
  end;
  if KeyIsDown(vkEsc) then halt;

  if KeyTrigger(vkSmallT) then
    writeln('tttttttttttttttttttttttttttt ----');

  // print FPS
  Fps.Tic;
  writeln(
    'FPS: '+inttostr(Fps.Effective),' ',
    'F1=',BoolToStr(KeyIsDown(vkF1),true)[1],' ',
    'F2=',BoolToStr(KeyIsDown(vkF2),true)[1],' ');

  // refresh
  glutSwapBuffers;
  Sleep(1000 div 20);
end;

procedure OnIdle; cdecl;
begin
  glutPostRedisplay;
end;

begin
  // OpenGL stuff  
  InitOpenGl;
  Fps.Limit := 20;
  Debug.Enable(dlInput);

  // start loops
  glutDisplayFunc(@OnDisplay);
  glutIdleFunc(@OnIdle);

  // main loop
  glutMainLoop;
end.
